package com.humngyang.com.hmy.study.concurrency.myannoations.filter;


import com.humngyang.com.hmy.study.concurrency.myannoations.ThreadSafe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;


//自定义一个过滤器，然后通过在启动类中配置使之拦截相应的请求路径
public class HttpFilter implements Filter {
    private static Logger log = LoggerFactory.getLogger(HttpFilter.class);
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        log.info("do filter {} ,{}", Thread.currentThread().getId(),request.getServletPath());
        ReuqestHolder.add(Thread.currentThread().getId());
        filterChain.doFilter(servletRequest,servletResponse);
    }

    @Override
    public void destroy() {

    }
}
